package com.dongdongshop.service.impl.evaluate;

import com.dongdongshop.pojo.evaluate.Evaluate;
import com.dongdongshop.service.evaluate.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class EvaluateServiceImpl implements EvaluateService {
    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public void insertEvaluate(Evaluate evaluate,String username) {
        evaluate.setCreateDate(new Date());
        evaluate.setUsername(username);
        mongoTemplate.save(evaluate);
    }

    @Override
    public List<Evaluate> listEvaluate(Long goodsId) {
        Query query = new Query(Criteria.where("goodsId").is(goodsId));
        return mongoTemplate.find(query,Evaluate.class);
    }
}
